﻿/*
 * @author: wizardc
 */

using Dou.Utils;
using DouEditor.Const;
using DouEditor.Resource.Common;

namespace DouEditor.Resource
{
    /// <summary>
    /// 开始打包
    /// </summary>
    public class BuildStep_Begin : BuildStepBase
    {
        private bool _isBuildABOrPackage;
        
        public BuildStep_Begin(bool isBuildABOrPackage)
        {
            _isBuildABOrPackage = isBuildABOrPackage;
        }
        
        protected override void Start()
        {
            BuildStepData buildStepData = null;
            BuildPackageStepData buildPackageStepData = null;
            if (_isBuildABOrPackage)
            {
                buildStepData = (BuildStepData) _buildStepData;
            }
            else
            {
                buildPackageStepData = (BuildPackageStepData) _buildStepData;
            }
            
            Log.MarkElapsedTime(BuildTimeConst.BuildAllTime);
            
            // 打包前的资源同名检测，需要通过后才能打包
            if (!new CheckResShortName().Check(_isBuildABOrPackage ? buildStepData.buildRule : buildPackageStepData.buildRule, out var error))
            {
                Failed(error);
                return;
            }
            
            Complete();
        }
    }
}
